<style>
.hook_info .row {
	margin-bottom: 4px;
}
</style>
<div class="page-content" >
	<div class="panel panel-default">
		<div class="panel-heading">
			<ul class="breadcrumb">
				<li><a href="<{:U('hook_index')}>">勾子管理</a></li>
				<li >创建/修改勾子</li>
			</ul>
		</div>
		<div class="panel-body">
			<form enctype="multipart/form-data" class="form-horizontal" action="<{:U('hook_add')}>" method="post" >
				 <input type="hidden" name="id" value="<{$data.id}>">
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">名称</label>
					<div class="col-sm-7">
						<input type="text" placeholder="hook(名称)，默认会调用hook目录" class="form-control" id="hook_name" name="hook_name" value="<{$data.hook_name}>">
					</div>
				</div>
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">备注</label>
					<div class="col-sm-7">
						<textarea name="remark" class="form-control"><{$data.remark}></textarea>
					</div>
				</div>
				
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">相关代码</label>
					<div class="col-sm-7">
						<textarea name="code" class="form-control" style="height:100px"><{$data.code}></textarea>
					</div>
				</div>
				
				
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">调用其它事件</label>
					<div class="col-sm-7 hook_info">
						<div class="row">
							<div class="col-sm-12"> <a href="#this" onClick="add_row()">添加</a> </div>
						</div>
						<volist name="data['info']" id="vo">
							<div class="row con_row">
								<div class="col-sm-4">
									<input type="text" placeholder="事件名称" class="form-control" value="<{$vo.name}>" name="info[<{$i}>][name]"  >
								</div>
								<div class="col-sm-4" style="margin-top:7px" >
									<label><input 
										<if condition="$vo['enable'] eq 1">checked</if>
										name="info[<{$i}>][enable]" type="radio" value="1">启用</label>
									<label><input 
										<if condition="$vo['enable'] eq 2">checked</if>
										name="info[<{$i}>][enable]" type="radio" value="2">禁用</label>
									<a href="#this" onClick="del_row(this)">删除</a>	
								</div>
								 
							</div>
						</volist>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-7">
						<button type="submit" class="btn btn-primary">保存</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script>
var len=$(".hook_info .con_row").length; 
if(len==0){
	add_row();
}
function add_row(){
	var html="";
	html+='<div class="row con_row">';
	html+='<div class="col-sm-4">';
	html+='<input type="text" placeholder="事件名称" class="form-control" name="info['+len+'][name]"  >';
	html+='</div>';
	html+='<div class="col-sm-4" style="margin-top:7px" >';
	html+='<label><input checked name="info['+len+'][enable]" type="radio" value="1">启用</label>';
	html+='<label><input name="info['+len+'][enable]" type="radio" value="2">禁用</label>';
	html+='<a href="#this" onClick="del_row(this)">删除</a>';
	html+='</div>';
	html+='</div>';
	$(".hook_info").append(html);
	len++;
	
} 
function del_row(obj){
	$(obj).parent().parent().remove();
}
$(function(){
    $(".form-horizontal").bootstrapValidator({
        message: '您填入的值不合法',
        fields:{
            
			hook_name: {
                message: '调用名称',
                validators: {
                    notEmpty: {
                        message: '调用名称不能为空'
                    },
                }
            },
			remark: {
                message: '备注',
                validators: {
                    notEmpty: {
                        message: '备注不能为空'
                    },
                }
            },
			 
			  

        }
    });
	
 
});
 </script> 
